package com.yfp.operation.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yfp.operation.domain.MachineDO;
import com.yfp.operation.domain.MachineInventoryWarnDO;
import com.yfp.operation.domain.dto.WarnParameterDTO;
import com.yfp.operation.domain.vo.MachineErrorVO;
import com.yfp.operation.service.MachineInventoryWarnService;
import com.yfp.operation.mapper.MachineInventoryWarnMapper;
import com.yfp.operation.mapper.MachineMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class MachineInventoryWarnServiceImpl extends ServiceImpl<MachineInventoryWarnMapper, MachineInventoryWarnDO> implements MachineInventoryWarnService {

    @Autowired
    private MachineMapper machineMapper;
    @Autowired
    private MachineInventoryWarnMapper machineInventoryWarnMapper;

    /**
     * 库存报警
     * @param warnParameterDTO
     * @return
     */
    @Override
    public List<MachineErrorVO> getMachineInventoryWarn(WarnParameterDTO warnParameterDTO) {

        // 获取设备名称
        MachineDO machine = machineMapper.getMachine(warnParameterDTO.getMachineId());
        // 库存
        List<MachineErrorVO> inventoryWarnList = machineInventoryWarnMapper.getMachinInventoryWarn(warnParameterDTO);
        inventoryWarnList.forEach(machineError -> {
            machineError.setMachineName(machine.getMachineName());
            machineError.setErrorType(warnParameterDTO.getStatus());
        });

        return inventoryWarnList;

    }
}
